//
//  PatForFlowLayout.m
//  随拍
//
//  Created by lanou3g on 16/1/18.
//  Copyright © 2016年 Ashoka. All rights reserved.
//

#import "PatForFlowLayout.h"

@implementation PatForFlowLayout

-(void)prepareLayout{
    self.itemSize = CGSizeMake(230, 220);
    self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.minimumLineSpacing = 30;
    
    
}

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
    return YES;
}

-(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
    
    NSArray *array = [super layoutAttributesForElementsInRect:rect];
    CGFloat centerX = self.collectionView.frame.size.width *0.5 + self.collectionView.contentOffset.x;
    for (UICollectionViewLayoutAttributes *attrs in array) {
        CGFloat itemCenterX = attrs.center.x ;
        
        CGFloat scale = 1 + 0.5 * (1 - ABS(itemCenterX - centerX)/200);
        
        attrs.transform3D = CATransform3DMakeScale(scale, scale, 1);
    }
    
    return array;
}

@end
